package cn.timeapi.Applet.Mall.CatSquare.common;

import cn.timeapi.Applet.Mall.CatSquare.entity.Account;
import cn.timeapi.Applet.Mall.CatSquare.util.SerializationUtil;
import org.apache.tomcat.jni.Time;
import redis.clients.jedis.Jedis;

/**
 * @description:
 * @author: Vincent Vic
 * @email: vincent-vic@qq.com
 * @time: 2020/10/5 19:15
 */

public class RedisStringJava {
    public static void main(String[] args) {
        //连接本地的 Redis 服务
        Jedis jedis = new Jedis("localhost");
        System.out.println("连接成功");
        Account account = new Account();
        account.setOpenId("111");

        //设置 redis 字符串数据
        jedis.set("u1".getBytes(), SerializationUtil.serialize(account));
        jedis.expire("u1".getBytes(),20);
        // 获取存储的数据并输出
        System.out.println("redis 存储的字符串为: "+ SerializationUtil.deserialize(jedis.get("user".getBytes())));
    }
}
